/*
 * @Author: szx
 * @Date: 2022-05-04 14:19:46
 * @LastEditTime: 2022-05-04 14:31:47
 * @Description:
 * @FilePath: \leetcode\剑指offerII\106\106.js
 */
/**
 * @param {number[][]} graph
 * @return {boolean}
 */
var isBipartite = function (graph) {
    const n = graph.length;
    const visited = new Array(n).fill(0);
    for (let i = 0; i < n; i++) {
        if (visited[i]) continue;
        const que = [i];
        visited[i] = 1;
        while (que.length) {
            const arr = graph[que.shift()];
            for (let j = 0; j < arr.length; j++) {
                if (visited[j] == -1) continue;
                else if (visited[j] == 1) return false;
                visited[j] = 0;
                que.push(j);
            }
        }
    }
    return true;
};
